/**
 * 表格默认配置
 * @returns 
 */
export const commonTableOptions = {
  border: true,
  index: true,
  editBtn: false,
  delBtn: false,
  indexLabel: '序号',
  stripe: true,
  menuAlign: 'center',
  searchMenuSpan: 12,
  align: 'center',
  viewBtn: false,
  card: false,
  columnBtn: false,
  menuWidth: 220,
  dialogClickModal: false,
  indexWidth: 90,
  searchLabelWidth: 100,
  labelWidth: 100,
  searchIcon: true,
  refreshBtn: false,
  searchMenuPosition: 'right',
  searchBtnText: '查 询',
  labelPosition: 'left',
  gutter: 24,
  searchGutter: 24,
  searchIndex: 3,
  searchShowBtn: false,
  searchBtn: false,
  emptyBtn: false,
  selection: false, // 可多选
  addBtn: false,
  menu: true,
  header: false,
  searchEnter: true,
  filterBtnNew: true,
  saveBtnIcon: " ",
  delBtn: false,
  tip: false,
  dialogMenuPosition: "center",
  dialogCustomClass: 'crud-dialog',
  isDialogFullscreen: false,
  column: [],
  // searchMenuSpan: 12,
}
const createCommonTableOption = () => {
  return {
    border: true,
    index: true,
    indexLabel: "序号",
    stripe: true,
    menuAlign: "center",
    searchMenuSpan: 12,
    align: "center",
    viewBtn: false,
    addBtn: false,
    editBtn: false,
    delBtn: false,
    card: false,
    columnBtn: false,
    menuWidth: 150,
    dialogClickModal: false,
    indexWidth: 70,
    searchLabelWidth: 0,
    labelWidth: 100,
    searchIcon: true,
    refreshBtn: false,
    searchMenuPosition: "right",
    searchBtnText: "查 询",
    labelPosition: "left",
    tip: false,
    gutter: 24,
    searchGutter: 24,
    searchIndex: 3,
    searchShowBtn: false,
    searchBtn: false,
    emptyBtn: false,
    menu: true,
    dialogCustomClass: "crud-dialog",
    selection: false,
    column: [],
  };
};

export const createTableOption = (option) => {
  const commonOption = createCommonTableOption();
  if (Array.isArray(option.column)) {
    option.column.forEach((col) => {
      if ((col.type === "input" || col.type === undefined) && col.maxlength === undefined) {
        col.maxlength = 20;
      } else if (col.type === "textarea" && col.maxlength === undefined) {
        col.maxlength = 200;
      }
    });
  }
  return {
    ...commonOption,
    ...option,
  };
};

/**
 * 表单默认配置
 * @returns 
 */
const createCommonFormOption = () => {
  return {
    span: 6,
    labelWidth: 120,
    labelPosition: "right",
    column: [],
  };
};


export const createFormOption = (option) => {
  const commonOption = createCommonFormOption();
  if (Array.isArray(option.column)) {
    option.column.forEach((col) => {
      if ((col.type === "input" || col.type === undefined) && col.maxlength === undefined) {
        col.maxlength = 20;
      } else if (col.type === "textarea" && col.maxlength === undefined) {
        col.maxlength = 200;
      }
    });
  }
  return {
    ...commonOption,
    ...option,
  };
};